﻿var Fantasy = {};

(function () {
    Fantasy.API = function () {

        var apiPath = "http://fantasy.servebeer.com:8888";
        
        var sendPutRequest = function(url, username, password, data)
        {
         
            $.ajax({
                    type: "PUT",
                    url: url,
                    contentType: "application/json",
                    username: username,
                    password: password,
                    dataType: 'jsonp',
                    data: data,
                    statusCode: {
                        202: function(data) {
                            console.log(data)
                        },
                        500: function(data){
                            console.log(data)
                        }
                    }
                });

        };

        return {   
                getWatchList: function() {
                    console.log("test");
                },
                swapPlayers: function(username, password, playerIn, playerOut) {
                    console.log("Player in: " + playerIn);
                    console.log("Player out: " + playerOut);

                    var url = apiPath + "/transfers";
                    var data = "{\"in\": \"" + playerIn + "\", \"out\":\"" + playerOut + "\"}";
                    sendPutRequest(url, username, password, data);
                }
        };
    };
})();
